 
//加载图表
$(function(){
	loadZdfxryxx();//12号位置
	loadDbxxTable();//2号位置
	setTimeout(function(){
		loadYwbl();//3号位置
		loadRygl();//4号位置
		loadJqzt();//5号位置
	},500)
})

var loadZdfxryxx = function(){
	$('#zdfxryxx').datagrid({
		url:"/kss_jbxx/jbxxList",
		queryParams: {
			'fxdj$in': '1,2,3',
			'xm':'',
			'snbh':'',
			'sort':'id',
			'order':'desc',
		} 
	}) 
}

var loadDbxxTable = function(){
	$('#dbryxxTable').datagrid({
		url:"/kss_process/getProcessTaskList",
		columns:[[
			{field:'jsbh',title:'监所编号',width:'25%',align:'center'},
			{field:'snbh',title:'人员编号',width:'25%',align:'center'},
			{field:'xm',title:'姓名',width:'25%',align:'center'},
			{field:'jsh',title:'监室号',width:'25%',align:'center'}, 
			{field:'xkwb',title:'代办流程',width:'25%',align:'center'}, 
	    ]],
	    queryParams: {
	    	'jsh':'',
	    	'snbh':'',
	    	'xm':'',
			'processDefinitionKey':"kss_emcx,kss_emsz,kss_jbjc,kss_jbsz,kss_jbyc,kss_jjf,kss_jjf,kss_jstz,kss_lsfx,kss_xjjc,kss_xjsz,kss_xjyc,kss_ygjc,kss_ygsz,kss_ygyc",
			'taskDefinitionKey':"",
			"rows" : function() {
				return $('#dbryxxTable').datagrid("getPager").pagination("options").pageSize;
			},
			"page" : function() {
				return $('#dbryxxTable').datagrid("getPager").pagination("options").pageNumber;
			}
		} 
	});
}

//添加tab
function addTab(title, url){
 //控制tabs的打开个数
	/*if(!hasmenu(auth)){
		$.messager.alert('提示','没有该模块权限,请联系管理员授权!','info');
		return;
	}*/
    var tab = $('#tt').tabs('tabs');
    var tabCount = tab.length;
    if (tabCount >= 8) {
    	$.messager.alert('提示','最多只能打开8个标签页,请首先关闭其他标签页,再继续操作.!','info');
    	return;
    }
	if ($('#tt').tabs('exists', title)){
		$('#tt').tabs('select', title);
	} else {
		var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%; "></iframe>';
		$('#tt').tabs('add',{
			title:title,
			content:content,
			closable:true
		});
	}
}

function refreshFrame(url){
  var tab = $('#tt').tabs('getSelected');
    $("#tt").tabs('update',{
        tab: tab,
        options:{
            href: url
        }
    });
    tab.panel('refresh');

}

//关闭所有的tab
    function closeAll(){
        var tiles = new Array();
          var tabs = $('#tt').tabs('tabs');
          var len =  tabs.length;
          if(len>0){
            for(var j=0;j<len;j++){
                var a = tabs[j].panel('options').title;
                tiles.push(a);
            }
            for(var i=1;i<tiles.length;i++){
                $('#tt').tabs('close', tiles[i]);
            }
          }
    }
//关闭其它
	function closeOther(){
        var tiles = new Array();
          var tabs = $('#tt').tabs('tabs');
          var tab = $('#tt').tabs('getSelected');
          var index = $('#tt').tabs('getTabIndex', tab);

          var len =  tabs.length;
          if(len>0){
            for(var j=0;j<len;j++){
                var a = tabs[j].panel('options').title;
                tiles.push(a);
            }

            for(var i=1;i<tiles.length;i++){
            	if (tiles[index]!=tiles[i]) {
                $('#tt').tabs('close', tiles[i]);
                }
            }
          }
    }
//关闭当前的tab
	function removePanel(){
		var tab = $('#tt').tabs('getSelected');
		var index = $('#tt').tabs('getTabIndex',tab);
			if(index=='0'){
				return false;
			}
		    if (tab){
			var index = $('#tt').tabs('getTabIndex', tab);
			$('#tt').tabs('close', index);
			}
		}
//双击关闭
	$(document).ready(function() {
	    $('#tt').bind('dblclick',function(){
	    	var tab = $('#tt').tabs('getSelected');
			var index = $('#tt').tabs('getTabIndex',tab);
				if(index=='0'){
					return false;
				}
	        var title = $('.tabs-selected').text();
	        $('#tt').tabs('close',title);
	    })
});

//右击显示菜单
	$(function(){
		$('#tt').bind('contextmenu',function(e){
			e.preventDefault();
			$('#contextMenu_jygl').menu('show', {
				left: e.pageX,
				top: e.pageY
			});
		});
	});

    $(".list_dt").on("click",function () {
        $('.list_dd').stop();
        $(this).siblings("dt").removeAttr("id");
        if($(this).attr("id")=="open"){
            $(this).removeAttr("id").siblings("dd").slideUp();
        }else{
            $(this).attr("id","open").next().slideDown().siblings("dd").slideUp();
        }
    });
   
	  
        var loadJqzt=function(){
	       	 var echartData2=new Array();
	       	 var echartData3=new Array();
	       	 $.ajax({
	       		 type : "post",
	       		 async : false,             		  //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）	         
	       		 url : "/kss_jbxx/getJszkCount",    //请求发送到
	       		 dataType : "json",        //返回数据形式为json	 
	       		 success : function(result) {
	       			 for(var i=0; i<result.rows.length; i++){
	       				 var jsStr=result.rows[i].jsh;
	       				 var jsCount=parseInt(result.rows[i].id);
	       	       		 echartData2.push(jsStr);
	       	       		 echartData3.push(jsCount);
	       			 }
	       		 },
	       	 }); 	        
       	       var myChart = echarts.init(document.getElementById('jqztid'));	
       	    window.onresize = myChart.resize;
       	    		option = {
       	    			   title : {
       	    			   	        text: '监室状况',
       	    			   	        subtext: '所内监室人数情况',
       	    			   	        x:'center'
       	    			   	    },
       	    			    tooltip : {
       	    			        trigger: 'axis'
       	    			    },
       	    			    calculable : true,
       	    			    xAxis : [
       	    			        {
       	    			            type : 'category',
       	    			            data : echartData2
       	    			        }
       	    			    ],
       	    			    grid: {
       	    			    	top:'85px',
       		     		    	right: '4%',
       		     		    	left: '4%',
       		     		        bottom: '3%',
       		     		        containLabel: true
       	        		    },
       	    			    yAxis : [
       	    			        {
       	    			         type : 'value'
       	    			        }
       	    			    ],
       	    			    series : [
       	    			    	{	
       	    			    		name:'监室人数',
       		    			        data:echartData3,
       		    			        type:'bar' 
       	    			    	}
       	    			    ]
       	    			}; 
       	    			                   
       		      myChart.setOption(option);
       		      myChart.resize(); 
       		      window.onresize = myChart.resize; 
       }

        function get7day(){
	  	  	var d=new Date();
	  	  	d.setDate(d.getDate()-6);
	  	  	var arr=[];
	  	  	for(var i=0; i<7; i++){
	  	 		arr.push(("0" + (d.getMonth() + 1)).slice(-2)+'-'+("0" + d.getDate()).slice(-2));
	  	  		d.setDate(d.getDate()+1);
	  	  	}
	  	  	return arr;
	  	}
        
	      var loadYwbl = function(){
	    	  var dateArr = get7day();
	    	  console.info('dateArr-----'+dateArr);
	    	  var myChart = echarts.init(document.getElementById('zzid'));		
	    	  window.onresize = myChart.resize;
	    	  var getNumWithLx = function(dateArr,array){
	          	var new_array = new Array();
	          	for(var i = 0; i < 7; i++){
	  				for (var k = 0; k < 7; k++) {
	  					if (dateArr[i] == array[k].tjsj) {
	  						new_array[i] = array[k].num;
	  						break;
	  					}else {
	  						new_array[i] = array[k].num;
	  					}
	  				}
	  			}
	          	var map = {
	          			'name' : array[0].lx,
	          			'value' : new_array,
	          	}
	          	return map;
	          };
	    	  $.ajax({
	    		  type : "get",
	    		  async : false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）	         
	    		  url : "kss_jcjl/getWeekCountByParams",    //请求发送到
	    		  data : {},
	    		  dataType : "json",        //返回数据形式为json	         
	    		  success : function(result) { 	
	    			var new_array0 = getNumWithLx(dateArr,result.thjy); 
	    			var new_array1 = getNumWithLx(dateArr,result.jstz); 
	    			var new_array2 = getNumWithLx(dateArr,result.yg); 
	    			var new_array3 = getNumWithLx(dateArr,result.zyaf); 
	    			var new_array4 = getNumWithLx(dateArr,result.jb); 
	    			var new_array5 = getNumWithLx(dateArr,result.xj); 
	    			var new_array6 = getNumWithLx(dateArr,result.wg); 
	    			var new_array7 = getNumWithLx(dateArr,result.em); 
	    			
	  	    	  var option = {
	  			    	  title : {
	  			    		  text: '业务办理',
	  			    		  // subtext: '所内业务办理次数',
	  			    		  x:'center'
	  			    	  },
	  			    	  tooltip : {
	  			    		  trigger: 'axis',
	  			    		  /*axisPointer : {    
	  			    			  type : 'shadow'        
	  			    		  }*/
	  			    	  },
	  			    	  legend: {
	  			    		  top:'30px',
	  			    	  },
	  			    	  grid: {
	  			    		  top:'85px',
	  			    		  right: '4%',
	  			    		  left: '4%',
	  			    		  bottom: '3%',
	  			    		  containLabel: true
	  			    	  },
	  			    	calculable : true,
	  			    	  xAxis: {
	  			    	      type: 'category',
	  			    	      data : get7day(),
	  			    	    },
	  			    	  yAxis: {
	  			    	        type: 'value'
	  			    	   },
	  			    	  series : [
	  						  {
	  							  name:new_array0.name,
	  							  type:'line',
	  							  data:new_array0.value,
	  						  },
	  						  {
	  							  name:new_array1.name,
	  							  type:'line',
	  							  data:new_array1.value,
	  						  },
	  						  {
	  							  name:new_array2.name,
	  							  type:'line',
	  							  data:new_array2.value,
	  						  },
	  						  {
	  							  name:new_array3.name,
	  							  type:'line',
	  							  data:new_array3.value,
	  						  },
	  						  {
	  							  name:new_array4.name,
	  							  type:'line',
	  							  data:new_array4.value,
	  						  },
	  						  {
	  							  name:new_array5.name,
	  							  type:'line',
	  							  data:new_array5.value,
	  						  },
	  						  {
	  							  name:new_array6.name,
	  							  type:'line',
	  							  data:new_array6.value,
	  						  },
	  						  {
	  							  name:new_array7.name,
	  							  type:'line',
	  							  data:new_array7.value,
	  						  },
	  						]
	  		    	  };

	  	    	  // 使用刚指定的配置项和数据显示图表。
	  	    	  myChart.setOption(option);
	       			myChart.resize(); 
	  	    	  window.onresize = myChart.resize;
	  	    	  
	    		  },
		    });
	      }
	      
	      var loadRygl = function(){
	    	  var myChart = echarts.init(document.getElementById('sxid'));
	    	  window.onresize = myChart.resize;
	    	  $.ajax({
	    		  type : "get",
	    		  async : false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）	         
	    		  url : "kss_jbxx/findJbxxNumByParams",    //请求发送到
	    		  data : {},
	    		  dataType : "json",        //返回数据形式为json	         
	    		  success : function(result) { 	
	    			  var arrays = new Array(); 
	    			  for(var i = 0; i < result.length; i++){
	    				  arrays[i] = {
	    						  value:result[i].value,
	    						  name:result[i].name
	    				  }
	    			  }
	    			  console.info('s---'+arrays.name);
	    			  // 所内事务（扇形图形）
	    			  option = {
	    					  title : {
	    						  text: '人员管理',
	    						  subtext: '所内各类人员',
	    						  x:'center'
	    					  },
	    					  tooltip : {
	    						  trigger: 'item',
	    						  formatter: "{a} <br/>{b} : {c} ({d}%)"
	    					  }, 
	    					  grid: {
	    						  right: '10%',
	    						  left: '90px',
	    						  bottom: '3%',
	    						  containLabel: true
	    					  },
	    					  legend: {
	    						  orient : 'vertical',
	    						  x : 'left',
	    						  data:arrays.name
	    					  },
	    					  calculable : true,
	    					  series : [
	    						  {
	    							  name:'访问来源',
	    							  type:'pie',
	    							  radius : '55%',
	    							  center: ['50%', '60%'],
	    							  data:arrays
	    						  }
	    						]
	    			  };	        	
	    			// 使用刚指定的配置项和数据显示图表。
	    	    	  myChart.setOption(option);	
	    	       			myChart.resize(); 
	    	    	  window.onresize = myChart.resize;	
	    		  },
	    	  })
	    	  
	      }
      
    //<!-- 首页留言簿新增 -->     	
      $(window).keydown(function(event) {
	      	if (event.keyCode == 13) {
	      		submitlyb();
	      	}
      });

      $(function(){
      	getLyxx();
      	tsBnwk();
      });

      function tsBnwk(){
      	document.getElementById("fasong").style.background="#AAAAAA";
      	$('#fasong').off("click").on("click",function(){
      		$.messager.alert("确定","留言不能为空","info");
      	})
      }

      function makeFsAble(){
      	var nrText = $("#nrfm").val();
      	new_nrText = nrText.trim().replace(/\s/g,"");
      	if(new_nrText.length == 0){
      		tsBnwk();
      	}else{
      		document.getElementById("fasong").style.background="#3399ff";
      		$('#fasong').off("click").on("click",function(){
      			submitlyb();
      		})
      	}
      }

      function getLyxx(){
      	var brrq = longTimeType(new Date());
      	  $.ajax({
      		    type : "post",
      		    //async : false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）	         
      		    url : "kss_lyb/syLybList",    //请求发送到
      		    data : {
      		    	state: 'R2',
      		    	'yxrq$gte': brrq,
      		    	'sort':'lysj',
      		    	'order': 'asc',
      		    }, 
      		    dataType : "json",        //返回数据形式为json	         
      		    success : function(result) { 	
      				var json = JSON.stringify(result);  
      				var jsonobj = JSON.parse(json, function (key, value){         
      				      return key.indexOf('date') >= 0 ? new Date(value) : value;    
      				}); 
      				
      				for(var key in jsonobj.rows){
      					var content_left = 	"<div class='leftd'>"+
      						    			"<div style='margin-top: 20px;float: left'>"+
      						    			"<span style='float: left'>"+jsonobj.rows[key].lyr+"</span>"+
      						    			"&nbsp;&nbsp;<span>"+jsonobj.rows[key].lysj+"</span>"+
      						  	  			"</div><br><div class='speech left' ng-class='speech left' style='margin-top: 5px;margin-left:15px;'>"+ jsonobj.rows[key].nr+"</div>"+
      						   				"</div>";
      					var content_right = "<div class='rightd'>"+
      						    			"<div style='margin-top: 20px;float: right'>"+
      						    			"<span>"+jsonobj.rows[key].lysj+"</span>"+
      						    			"&nbsp;&nbsp;<span style='float: right'>"+jsonobj.rows[key].lyr+"</span>"+
      						  	  			"</div><br><div class='speech right' ng-class='speech right' style='margin-top: 5px;margin-right:15px;'>"+ jsonobj.rows[key].nr+"</div>"+
      						   				"</div>";
      			       if(jsonobj.rows[key].lyr == $('#userName').val()){
      			    	   $("#lybDiv").append(content_right);
      			       }else{
      			    	   $("#lybDiv").append(content_left);
      			       }
      						   				
      			     }
      		     },
      		 }) 
      }

      function goToButtom(){
      	var obj = document.getElementById("lybDiv");
      	obj.scrollTop= obj.scrollHeight;
      }

      function submitlyb(){
      	var str = longTimeType(new Date());
      	var lyr = $("#userName").val()
      	var lysj = str;
      	var yxrq = getLongDatePlus(lysj,2);
      	var nr = $("#nrfm").val();
      	
      	var content_right = "<div class='rightd'>"+
      						"<div style='margin-top: 20px;float: right'>"+
      						"<span>" + lysj + "</span>"+
      						"&nbsp;&nbsp;<span style='float: right'>" + lyr + "</span>"+
      						"</div><br><div class='speech right' ng-class='speech right' style='margin-top: 5px;margin-right:15px;'>" + nr + "</div>"+
      						"</div>";
      	
      	
      	 $.ajax({ 	
               type : "POST",  //提交方式  
               url : "/kss_lyb/lybAdd",//路径  
               data : {
                 	 "lyr" : lyr,
              	 "lysj" : lysj,
              	 "yxrq" : yxrq,
              	 "yxts" : "2",
              	 "nr" : nr
               },
               success : function(result) {
                    if (result.success) {   	 
                  		//getLyxx();
                  		$("#lybDiv").append(content_right);
      	            	$("#nrfm").val("");
      	            	makeFsAble();
      	            	goToButtom();
                    }else{     
      	        		$.messager.alert("确定","留言失败","info");                     
          
                    }     
               }   
           });
      };
      
      